package org.example.game.history;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/05 11:16
 */
public class Solution100283 {

    public static void main(String[] args) {
        System.out.println(new Solution100283().minAnagramLength("cdef"));

    }

    public int minAnagramLength(String s) {
        HashMap<String, Integer> wordNum = new HashMap<>();
        for(int i=0;i<s.length();i++){
            String subWord = s.substring(i,i+1);
            if(!wordNum.containsKey(subWord)){
                wordNum.put(subWord, 0);
            }
            wordNum.put(subWord, wordNum.get(subWord) + 1);
        }

        return minSum(wordNum);
    }

    private int minSum(HashMap<String, Integer> wordNum) {

        Boolean flag = true;
        while (flag){
            for(Integer value : wordNum.values()){
                if(value % 2 != 0){
                    flag = false;
                    continue;
                }
            }

            if(flag){
                for(String key : wordNum.keySet()){
                    wordNum.put(key, wordNum.get(key)/2);
                }
            }
        }

        flag = true;
        while (flag){
            for(Integer value : wordNum.values()){
                if(value % 3 != 0){
                    flag = false;
                    continue;
                }
            }

            if(flag){
                for(String key : wordNum.keySet()){
                    wordNum.put(key, wordNum.get(key)/3);
                }
            }
        }

        flag = true;
        while (flag){
            for(Integer value : wordNum.values()){
                if(value % 5 != 0){
                    flag = false;
                    continue;
                }
            }

            if(flag){
                for(String key : wordNum.keySet()){
                    wordNum.put(key, wordNum.get(key)/5);
                }
            }
        }

        flag = true;
        while (flag){
            for(Integer value : wordNum.values()){
                if(value % 7 != 0){
                    flag = false;
                    continue;
                }
            }

            if(flag){
                for(String key : wordNum.keySet()){
                    wordNum.put(key, wordNum.get(key)/7);
                }
            }
        }

        int result = 0;

        for(Integer value : wordNum.values()){
            result+=value;
        }

        return result;
    }

}
